package online.acutuator.health;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

/**
 * @Auther: 狼芒
 * @Date: 2021/9/15 22:01
 * @Descrintion: 自定义health健康监测
 * @version: 1.0
 */
@Slf4j
@Component
public class MyComHealthIndicator extends AbstractHealthIndicator {

    /**
     * 真是的检查方法
     *
     * @param builder
     * @throws Exception
     */
    @Override
    protected void doHealthCheck(Health.Builder builder) throws Exception {
        Map<String, Object> map = new HashMap<>();
        map.put("name", "张三");
        map.put("age", 18);
        map.put("lenth", 18);
        map.put("height", 180);
        map.put("weight", 160);
        //mongodb 获取连接进行测试
        int flag = new Random().nextInt();
        log.error(flag + "---" + (flag % 2 == 0));
        if (flag % 2 == 0) {
            builder.up();
        } else {
            builder.down();
        }
        builder.withDetail("code", 200).withDetails(map);

    }
}
